
#include "combinatorio.h"

#include <cmath>
#include <cassert>

#include "auxmath.h"

using namespace Math;

Combinatorio::Combinatorio(int n) {
   assert(n >= 0);
   this->n = n;

   coeficientes = new float[n+1];

   float gradoFactorial = factorial(n);
   float sum = 0;
   for(int i = 0; i < n+1; ++i){
      coeficientes[i] = gradoFactorial / (factorial(i) * factorial(n - i));
      sum += coeficientes[i];
   }

   assert(fabs(sum - pow(2, n)) < 0.001);

}

float Combinatorio::operator()(int i) const {
   assert(i >= 0);
   assert(i <= n+1);

   return coeficientes[i];
}

Combinatorio::~Combinatorio() {
   if(coeficientes) {
      delete[] coeficientes;
   }
}

